BX.namespace("BX.UI");if(typeof BX.UI.Form==="undefined"){BX.UI.Form=function(){this._id="";this._settings=null;this._elementNode=null;this._formData=null};BX.UI.Form.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:"";this._settings=BX.type.isPlainObject(e)?e:{};this._elementNode=BX.prop.getElementNode(this._settings,"elementNode",null);this._formData=BX.prop.getObject(this._settings,"formData",null);if(!this._elementNode&&!this._formData){throw"BX.UI.Form: Could not find 'elementNode' or 'formData' parameter in settings."}this.doInitialize()},doInitialize:function(){},getId:function(){return this._id},getElementNode:function(){return this._elementNode},submit:function(t){if(!BX.type.isPlainObject(t)){t={}}var e={cancel:false,options:t};BX.onCustomEvent(this,"onBeforeSubmit",[this,e]);if(e["cancel"]){return false}this.doSubmit(t);BX.onCustomEvent(this,"onAfterSubmit",[this,{options:t}]);return true},doSubmit:function(t){}}}if(typeof BX.UI.AjaxForm==="undefined"){BX.UI.AjaxForm=function(){BX.UI.AjaxForm.superclass.constructor.apply(this);this._config=null};BX.extend(BX.UI.AjaxForm,BX.UI.Form);BX.UI.AjaxForm.prototype.doInitialize=function(){this._config=BX.prop.getObject(this._settings,"config",null);if(!this._config){throw"BX.UI.AjaxForm: Could not find 'config' parameter in settings."}if(BX.prop.getString(this._config,"url","")===""){throw"BX.UI.AjaxForm: Could not find 'url' parameter in config"}if(BX.prop.getString(this._config,"method","")===""){this._config["method"]="POST"}if(BX.prop.getString(this._config,"dataType","")===""){this._config["dataType"]="json"}};BX.UI.AjaxForm.prototype.getUrl=function(){return BX.prop.getString(this._config,"url","")};BX.UI.AjaxForm.prototype.setUrl=function(t){this._config["url"]=t};BX.UI.AjaxForm.prototype.addUrlParams=function(t){if(BX.type.isPlainObject(t)&&Object.keys(t).length>0){this._config["url"]=BX.util.add_url_param(BX.prop.getString(this._config,"url",""),t)}};BX.UI.AjaxForm.prototype.doSubmit=function(t){if(!this._elementNode){var e=BX.clone(this._config);if(!e.data){e.data={}}e.data=BX.merge(e.data,this._formData);BX.ajax(e)}else{BX.ajax.submitAjax(this._elementNode,this._config)}};BX.UI.AjaxForm.create=function(t,e){var i=new BX.UI.AjaxForm;i.initialize(t,e);return i}}if(typeof BX.UI.ComponentAjax==="undefined"){BX.UI.ComponentAjax=function(){BX.UI.ComponentAjax.superclass.constructor.apply(this);this._className="";this._actionName="";this._signedParameters=null;this._callbacks=null;this._getParameters={}};BX.extend(BX.UI.ComponentAjax,BX.UI.Form);BX.UI.ComponentAjax.prototype.doInitialize=function(){this._className=BX.prop.getString(this._settings,"className","");this._actionName=BX.prop.getString(this._settings,"actionName","");this._signedParameters=BX.prop.getString(this._settings,"signedParameters",null);this._callbacks=BX.prop.getObject(this._settings,"callbacks",{})};BX.UI.ComponentAjax.prototype.addUrlParams=function(t){if(BX.type.isPlainObject(t)&&Object.keys(t).length>0){this._getParameters=BX.merge(this._getParameters,t)}};BX.UI.ComponentAjax.prototype._prepareFormData=function(t,e,i){for(var n in t){var o=i!==""?i+"["+n+"]":n;if(BX.type.isPlainObject(t[n])||BX.type.isArray(t[n])){this._prepareFormData(t[n],e,o)}else{e.append(o,t[n])}}};BX.UI.ComponentAjax.prototype.makeFormData=function(t){var e=new FormData;this._prepareFormData(t,e,"");return e};BX.UI.ComponentAjax.prototype.doSubmit=function(t){var e=this._elementNode?BX.ajax.prepareForm(this._elementNode):{data:BX.clone(this._formData),filesCount:0};if(BX.type.isPlainObject(t.data)){for(var i in t.data){if(t.data.hasOwnProperty(i)){e.data[i]=t.data[i]}}}var n=e.filesCount>0?this.makeFormData(e):e;BX.ajax.runComponentAction(this._className,this._actionName,{mode:"class",signedParameters:this._signedParameters,data:n,getParameters:this._getParameters}).then(function(t){var e=BX.prop.getFunction(this._callbacks,"onSuccess",null);if(e){BX.onCustomEvent(window,"BX.UI.EntityEditorAjax:onSubmit",[t["data"]["ENTITY_DATA"],t]);e(t["data"])}}.bind(this)).catch(function(t){var e=BX.prop.getFunction(this._callbacks,"onFailure",null);if(!e){return}var i=[];var n=t["errors"];for(var o=0,a=n.length;o<a;o++){i.push(n[o]["message"])}BX.onCustomEvent(window,"BX.UI.EntityEditorAjax:onSubmitFailure",[t["errors"]]);e({ERRORS:i})}.bind(this))};BX.UI.ComponentAjax.create=function(t,e){var i=new BX.UI.ComponentAjax;i.initialize(t,e);return i}}
//# sourceMappingURL=form.map.js